package com.yonyou.cloud.member.config;

import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.Collections;

@Configuration
public class SwaggerAutoConfig {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                //.apis(RequestHandlerSelectors.basePackage(UserController.class.getPackage().getName()))
//                .paths(Predicates.or(PathSelectors.ant("/user/add"),
//                        PathSelectors.ant("/user/find/*")))
//                .apis(RequestHandlerSelectors.any())
                //.paths(PathSelectors.any())
                .build().apiInfo(apiInfo());
//        .useDefaultResponseMessages(false)
//                .globalResponseMessage(RequestMethod.GET, newArrayList(
//                        new ResponseMessageBuilder()
//                                .code(500)
//                                .message("服务器发生异常")
//                                .responseModel(new ModelRef("Error"))
//                                .build(),
//                        new ResponseMessageBuilder()
//                                .code(403)
//                                .message("资源不可用")
//                                .build()
//                ));
    }

    private ApiInfo apiInfo() {
        return new ApiInfo(
                "用户管理OpenAPI文档",
                "主要负责用户管理，内容包括用户维护、登录",
                "API V1.0",
                "",
                new Contact("峰哥", "", "zhaoyf@yonyou.com"),
                "", "",
                Collections.emptyList());
    }
}
